package algorithm;

import java.util.HashMap;
import java.util.Map;
import bean.Credit_parameter;
public class Swimming_credit {
	//参数顺序（游泳用时以秒为单位)，游泳距离，游泳等级，过往记录）
	public Map<String, Double> Get_swimming_score(int swimming_time,int swimming_distance,int swimming_level,double swimming_record){
		Map<String,Double> map = new HashMap<String,Double>();
		
		//对游泳结果的判断，包括了游泳速度和游泳距离两方面加成
		double velocity = swimming_distance * 60 / swimming_time;
		if(velocity <= 50){
			velocity = 0.4 * velocity;
		}
		else if(velocity > 50 && velocity <= 100){
			velocity = 0.8 * velocity - 20;
		}
		else if(velocity > 100){
			velocity = 60;
		}
		
		if(swimming_distance <= 800){
			velocity = velocity + swimming_distance / 20;
		}
		else if(swimming_distance > 800){
			velocity = velocity + 40;
		}
		
		//游泳比赛规则
		if(swimming_level <= Credit_parameter.getMatch_level_1() ){
			swimming_level = Credit_parameter.getMatch_level_1();
		}
		else if(swimming_level >= Credit_parameter.getMatch_level_2() && swimming_level <= Credit_parameter.getMatch_level_1()){
			swimming_level = Credit_parameter.getMatch_level_2();
		}
		else if(swimming_level >= Credit_parameter.getMatch_level_3() && swimming_level <= Credit_parameter.getMatch_level_4()){
			swimming_level = Credit_parameter.getMatch_level_3();
		}
		else if(swimming_level >= Credit_parameter.getMatch_level_4()){
			swimming_level = Credit_parameter.getMatch_level_4();
		}
		double swimming_Credit = (Credit_parameter.getProfession_swimming_result_weight() * velocity + 
		        (1 - Credit_parameter.getProfession_swimming_result_weight()) * swimming_level) * 
		        (1 - Credit_parameter.getProfession_swimming_record_weight());
		double swimming_Record = Credit_parameter.getProfession_swimming_record_weight() * swimming_record +
		        swimming_Credit;
		map.put("swimming_credit",swimming_Credit);
		map.put("swimming_record", swimming_Record);
		
		//判断积分是否变化
		double flag;
		if(swimming_Credit == 0){     //flag标志，0表示积分无变化
			flag = 0;
		}
		else{
			flag = 1;
		}
		map.put("flag", flag);          //flag标志，1表示积分无变化
		return map;
	}
}
